<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 插件 (Plugins) 是一种能为 Vue 添加全局功能的工具代码 -->
      <h2>插件</h2>
      <p>{{ count }}</p>
      <my-header></my-header>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const app = createApp({
        data() {
          return {};
        },
        inject: ["count"],
        mounted() {
          console.log(this.$abc);
          this.$fn();
        },
      });

      // 使用插件
      app.use({
        install(app, options) {
          // 添加全局属性
          app.config.globalProperties.$abc = 123;
          // 添加全局方法
          app.config.globalProperties.$fn = () => {
            console.log("fn");
          };
          // 添加全局组件
          app.component("MyHeader", {
            template: `
              <div>headerrr</div>
            `,
          });
          // 添加全局指令
          app.directive("focus", (el) => {
            el.focus();
          });
          // 添加全局依赖
          app.provide("count", 10);
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
